#pragma once

#include "Parameter.h"


class k_CheckBoxParameter
	: public k_BaseParameter
	, public ICheckBoxParameter
{
public:
	k_CheckBoxParameter(IDirect3D9BasePlugin& ar_Plugin, int ai_Id, const std::wstring& as_Name, const std::wstring& as_DisplayText, const std::wstring& as_Description, bool ab_Default)
		: k_BaseParameter(ar_Plugin, ai_Id, as_Name, as_DisplayText, as_Description, r_ParameterType::CheckBox)
		, mb_Default(ab_Default)
		, mb_Current(ab_Default)
	{
		this->UpdateDisplayText();
	}

	// IObject
	void* QueryInterface(const GUID& ar_InterfaceGuid)
	{
		if (ar_InterfaceGuid == __uuidof(ICheckBoxParameter)) 
			return static_cast<ICheckBoxParameter*>(this);

		return k_BaseParameter::QueryInterface(ar_InterfaceGuid); 
	}

	// ISliderParameter
	virtual void set_DefaultValue(bool ab_Value)
	{
		mb_Default = ab_Value;
	}

	virtual bool get_DefaultValue() const
	{
		return mb_Default;
	}

	virtual void set_CurrentValue(bool ab_Value)
	{
		mb_Current = ab_Value;
		this->UpdateDisplayText();
		mr_Plugin.OnParameterHasChanged(*this);
	}

	virtual bool get_CurrentValue() const
	{
		return mb_Current;
	}
	
	virtual void ResetToDefault()
	{
		mb_Current = mb_Default;
		this->UpdateDisplayText();
		mr_Plugin.OnParameterHasChanged(*this);
	}

	virtual std::wstring ToString()
	{
		return mb_Current ? L"true" : L"false";
	}

	virtual void FromString(const std::wstring& as_Value)
	{
		mb_Current = as_Value == L"true";
	}

protected:
	void UpdateDisplayText()
	{
		ms_DisplayText = ms_RawDisplayText + L": " + ToString();
	}

	bool mb_Default;
	bool mb_Current;
};
